package com.example.a16478082;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class LoginActivity extends AppCompatActivity {
    private Button btn_signUp;
    private EditText et_un,et_psd;
    private TextView tv_signIn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        initView();
        btn_signUp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent();
                intent.setClass(LoginActivity.this, MenuActivity.class);
                String username=et_un.getText().toString();
                String password=et_psd.getText().toString();
                if(username.equals("")||password.equals("")){
                    Toast.makeText(getApplicationContext(),"用户名或密码不能为空",Toast.LENGTH_SHORT).show();
                }else{
                    LoginActivity.this.startActivity(intent);
                }

            }
        });

        et_un.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View view, boolean b) {
                if(!b){
                    String username=et_un.getText().toString();
                    if(username.equals("")){
                        Toast.makeText(getApplicationContext(),"用户名不能为空",Toast.LENGTH_SHORT).show();
                    }else{
                        Toast.makeText(getApplicationContext(),username+"",Toast.LENGTH_SHORT).show();
                    }
                }
            }
        });
        et_psd.setOnFocusChangeListener(new View.OnFocusChangeListener(){
            @Override
            public void onFocusChange(View view,boolean b){
                if(!b){
                    String password=et_psd.getText().toString();
                    if(password.equals("")){
                        Toast.makeText(getApplicationContext(),"密码不能为空",Toast.LENGTH_SHORT).show();
                    }else{
                        Toast.makeText(getApplicationContext(),password+"", Toast.LENGTH_SHORT).show();
                    }
                }
            }
        });
        tv_signIn.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view){
                Intent intent=new Intent();
                intent.setClass(LoginActivity.this,RegisterActivity.class);
                LoginActivity.this.startActivity(intent);
            }
        });
    }

    private void initView() {
        btn_signUp=findViewById(R.id.btn_signUp);
        et_un=findViewById(R.id.et_un);
        et_psd=findViewById(R.id.et_psd);
        tv_signIn=findViewById(R.id.tv_signIn);
    }
}
